package com.cblue.jobs;

import com.alibaba.fastjson.JSONObject;
import com.cblue.pojo.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Collection;
import java.util.Map;

/**
 * ClassName:ClearImgJob
 * Author:maodi
 * CreateTime:2021/01/21/17:23
 */
public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;

    public void clearImg() {
        Jedis jedis = jedisPool.getResource();
        Map<String, String> map = jedis.hgetAll("teacher");
        if (map != null && map.size() > 0) {
            Collection<String> values = map.values();
            for (String value : values) {
                Teacher role = JSONObject.parseObject(value, Teacher.class);
//                             List<Course> courses = role.getCourses();
//                             for (Course cours : courses) {
                if (Integer.parseInt(role.getAge())>30) {
                    jedis.hdel("teacher", role.getId() + "");
                    System.out.println("已清理" + value + "信息");
                }
//                             }
            }
//            for (String value : values) {
//                Role role = JSONObject.parseObject(value, Role.class);
//                if (("556".equals(role.getName()))){
//                    jedis.hdel("Role", role.getName());
//                    System.out.println("已清理  "+value+"信息");
//                }
//            }
            jedis.close();
        }
    /*    Set<String> imageNames = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (imageNames != null) {
            for (String imageName : imageNames) {
                QiniuUtils.deleteFileFromQiniu(imageName);
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES, imageName);
                System.out.println("任务执行完毕，清理了垃圾图片："+imageName);
            }
        }*/
    }
}
